/***********************************Jieli tech************************************************
  File : startup.S
  By   : Juntham
  date : 2015-08-21 09:06
********************************************************************************************/
//#include "os_cfg.h"

.section .stack, "a"
         .space 0x300
         .global _stack_ssp
_stack_ssp:

.section .stack, "a"
         .space 0x500
         .global _stack_usp
_stack_usp:

#define hi(x) (x)>>16
#define lo(x) (x)&0xffff

.section .startup.text, "ax"
    .align 2
    .global _start
    .type _start,@function
    .org 0

_start:
cpu0_start:
    call boot_info_init

    sp = _stack_usp  ;// for idle
    ssp = _stack_ssp   ;// for interrupt

    r3 = bss_begin  ;//movh  r0, bss_begin
    r1 = 0          ;//mov   r1,0
    r2 = bss_size   ;//movh  r2, bss_size
    r2 >>= 2;
1:
    rep r2{
        [r3++] = r1
    }
    if(r2 != 0) goto 1b

    r3 = bss1_begin
    r1 = 0
    r2 = bss1_size
    r2 >>= 2;
1:
    rep r2{
        [r3++] = r1
    }
    if(r2 != 0) goto 1b

    r4 = data_addr  ;//movh  r0, data_addr
    r1 = data_begin ;//movh  r1, data_begin
    r2 = data_size ;//movh  r2, data1_size
    r2 >>= 2;
1:
    rep r2{
        r3 = [r1++]
        [r4++] = r3
    }
    if(r2 != 0)goto 1b

     r2 = icfg
     r2 &= 0xfffffcff
     r2 |= 0x100
     icfg = r2



    .extern main
    r0= main
    goto r0



// 在 startup.S 里面添加下面的代码

.extern exception_analyze
// void exception_analyze(unsigned *sp)
.global exception_irq_handler
.type exception_irq_handler, @function
//.section .volatile_ram_code
exception_irq_handler:
	[--sp] = {reti, rete, retx, rets, psr, icfg, usp, ssp}
	[--sp] = {r15-r0}

	r0 = sp // 把当前 sp 的值作为参数传递给解析函数
    call exception_analyze

1:
	goto 1b // 死循环



